import javax.print.attribute.standard.MediaSize;
import java.util.*;

public class NGuessNumber {
    static Scanner scanner = new Scanner(System.in);
    static Random random = new Random();

    // 在 NGuessNumber.java 中创建 generateAnswer 方法，它的功能是：
    // 随机生成4个0-9之间的不重复的整型数作为答案并返
    public static List<Integer> generateAnswer(){
        List<Integer> list = new LinkedList<>();
        do{
            int num = random.nextInt(10);
            if(!list.contains(num)){
                list.add(num);
            }
        }while (list.size() <= 3);
        return list;
    }

    // 它的功能是：接收玩家输入的4个数字并返回。
    public static List<Integer> getPlayerInput(){
        List<Integer> list = new LinkedList<>();
        for (int i = 0; i < 4; i++) {
            list.add(scanner.nextInt());
        }
        return list;
    }

//    比较玩家猜测和答案后返回提示信息。
    public static int compareGuessAnswer(List<Integer> ls1,List<Integer> ls2){
        int num = 0;
        for (int i = 0; i < 4; i++) {
            if(ls1.get(i).equals(ls2.get(i))){
                num++;
            }else {
            }
        }
        System.out.print("您输入的:");
        System.out.println(ls2);
        System.out.print("A=");
        System.out.println(num);
        return num;
    }

//    实现isWin方法，它的功能是：根据提示信息中A的数量判断玩家是否获胜，如果获胜返回true，否则返回false。
    public static boolean isWin(int num){
        if (num == 4){
            return true;
        }
        return false;
    }



    public static void main(String[] args) {



        boolean code = true;
        do{
            List<Integer> ls1 = NGuessNumber.generateAnswer();
            System.out.print("生成的答案:");
            System.out.println(ls1);

            int nums = 0;
            while (nums < 10){

                System.out.println("输入猜测数字:");
                List<Integer> ls2 = NGuessNumber.getPlayerInput();

                int num = NGuessNumber.compareGuessAnswer(ls1,ls2);
                if (isWin(num)){
                    System.out.println("获胜!");
                    break;
                }

                nums++;

            }

            System.out.println("继续游戏输入true/false:");
            code = scanner.nextBoolean();


        }while (code);




    }
}
